#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

const int N = 1e4 + 10, M = 1e6;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
struct node
{
    int u, w, f;
};

vector<node> edges[N];
int dist[N];
bool st[N];
int n, m;
int dijkstra(int minf)
{
    memset(st, 0, sizeof st);
    for(int i = 0; i <= n; i++) dist[i] = INF;
    priority_queue<PII, vector<PII>, greater<PII>> q; 
    dist[1] = 0;
    q.push({0, 1}); // 当前最短路 节点 
    while(q.size())
    {
        auto t = q.top(); q.pop();
        int u = t.second;
        if(st[u]) continue;
        st[u] = true;
        for(auto& t : edges[u])
        {
            int v = t.u, w = t.w, f = t.f;
            if(f < minf) continue;
            if(dist[u] + w < dist[v])
            {
                dist[v] = dist[u] + w;
                q.push({dist[v], v});
            } 
        }
    }
    return dist[n];
}

int main()
{
     cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int u, v, w, f; cin >> u >> v >> w >> f;
        edges[u].push_back({v, w, f});
        edges[v].push_back({u, w, f});
    }
    int ans = 0;
    for(int minf = 1; minf <= 1000; minf++)
    {
        int c = dijkstra(minf);
        if(c == INF) continue;
        ans = max(ans, M * minf / c);
    }
    cout << ans << endl;

    return 0;
}